// 云函数入口文件
const cloud = require('wx-server-sdk')
const cheerio =require('cheerio')//操作html模块
let charset =require('superagent-charset')//解决乱码
let superagent=require('superagent')//发起请求
const { load } = require('cheerio')
charset(superagent)//发起请求html通常乱码现在加一个解决乱码
cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  let serverUrl =`https://m.hiyd.com/${event.url}`
  const result =await superagent.get(serverUrl).charset('utf-8');
  const data =result.text || '';//没拿到返回一个空字符串
  const $ =cheerio.load(data)
  let videoobj ={}
  videoobj['video'] = $('.page-action').find('.action-video').find('video').attr('src')
  videoobj['pre'] =$('.page-action').find('.action-detail').find('pre').text()
  videoobj['title']=$('.page-action').find('.action-info').find('.info-hd').find('h4').text()
  return videoobj
}